{# This page accepts the following params: #}
{#    competition: The competition to display #}
{#    managed: True to display admin options #}

{% load static %}
{% load humanize %}

<a href="{% url "competitions:view" pk=competition.pk %}">
    <div class="competition-tile full-width">
        <input id="competitionID" type="hidden" value="{{ competition.id }}"/>
        <div class="row">
            <div class="col-sm-2 col-md-2">
                <div class="img-container">
                    {% if competition.image_url == None %}
                        <img src="{% static 'img/ProfileImageDummy.jpg' %}" class="img-responsive">
                    {% else %}
                        <img src="{{ competition.image_url }}" class="img-responsive">
                    {% endif %}
                </div>
            </div>
            <div class="col-sm-6 col-md-6">
                <h3>{{ competition.title }}</h3>
                <p class="organizer">Organized by {{ competition.creator }}</p>
                <p>{{ competition.description|truncatewords_html:20 }}</p>
            </div>
            <div class="col-sm-4 col-md-4 right-panel">
                {{ competition.get_start_date|date:"M d, Y" }}-{% if competition.end_date %}{{ competition.end_date|date:"M d, Y" }}{% else %}
                <i>No end date</i>{% endif %}<br>

                {% if competition.num_participants %}
                    {# try and use prefected participant count #}
                    <b>{{ competition.num_participants }}</b> participant{% if competition.num_participants > 1 %}s{% endif %}<br>
                {% else %}
                    <b>{{ competition.get_participant_count }}</b> participant{% if competition.get_participant_count > 1 %}s{% endif %}<br>
                {% endif %}


                {% if competition.reward and competition.reward > 0 %}
                    USD <b>${{ competition.reward|intcomma }}</b> reward
                {% endif %}
            </div>

            <br><br>
        </div>
        <div class="row">
            {% if managed %}
                <div class="competition-actions" published="{{ competition.published }}" class="columns cursor-default myCompetitionButtons">
                    <div class="btn-group btn-group-justified">
                        {% if request.user == competition.creator %}
                            <a class="btn btn-sm btn-danger" id="competition-delete-button" href="{% url 'competitions:delete' pk=competition.pk %}">Delete</a>
                        {% endif %}
                        <a class="btn btn-sm btn-primary" href="{% url 'competitions:edit' pk=competition.pk %}">Edit</a>
                        <a class="btn btn-sm btn-success competition-publish-button {% if competition.published %}hide{% endif %}" href="{% url 'competition-publish' pk=competition.pk %}">Publish</a>
                        <a class="btn btn-sm btn-warning competition-unpublish-button {% if not competition.published %}hide{% endif %}" href="{% url 'competition-unpublish' pk=competition.pk %}">Unpublish</a>
                        <a class="btn btn-sm btn-primary" href="{% url 'my_competition_participants' competition_id=competition.pk %}">Participants</a>
                        <a class="btn btn-sm btn-primary" href="{% url 'my_competition_submissions' competition_id=competition.pk %}">Submissions</a>
                        <a class="btn btn-sm btn-primary" href="{% url 'competitions:dumps' competition_pk=competition.pk %}">Dumps</a>
                    </div>
                </div>
            {% endif %}
        </div>
    </div>
</a>